package LeetCode.exercise;

import java.util.Arrays;

public class LC17_19 {
    public static void main(String[] args) {
        int[] arr  = missingTwo(new int[]{2,3});
        System.out.println(Arrays.toString(arr));
    }
    public static int[] missingTwo(int[] nums) {
        int tmp = 0;
        int len = nums.length;
        for (int i = 0; i < nums.length; i++) {
            tmp ^= nums[i];
        }
        for (int i = 1; i <= nums.length + 2; i++) {
            tmp ^= i;
        }
        int cur = tmp;
        tmp = tmp & (-tmp);
        int res1 = 0, res2 = 0;
        for(int i = 0; i < len; i++){
            if((tmp & nums[i]) == 0) {
                res1 ^= nums[i];
            } else {
                res2 ^= nums[i];
            }
        }
        for (int i = 1; i <= len+2; i++) {
            if((tmp & i) == 0) {
                res1 ^= i;
            } else {
                res2 ^= i;
            }
        }
        return new int[]{res1, res2};
    }
}
